#pragma semicolon 1
#pragma newdecls required
#include <sourcemod>
#include <sdktools>
#include <colors>



#define PLUGIN_NAME                   "l4d2_tank_limit_kk"    //这里写插件名字
#define PLUGIN_AUTHOR                 "豆瓣酱な"                         //作者
#define PLUGIN_DESCRIPTION            "每回合坦克数量限制"   //介绍
#define PLUGIN_VERSION                "1.1"
#define PLUGIN_URL                    "https://gitee.com/sweet-and-sour-bombs"  //网站

public Plugin myinfo =
{
    name        = PLUGIN_NAME,
    author      = PLUGIN_AUTHOR,
    description = PLUGIN_DESCRIPTION,
    version     = PLUGIN_VERSION,
    url         = PLUGIN_URL
}
ConVar l4d2_hCvar_tanklimit;

int RoundTankLimit;
int RoundTankNum;



public void OnPluginStart()
{
	HookEvent("tank_spawn", Event_Tank_Spawn, EventHookMode_Pre);  //tank出生事件。
	HookEvent("round_start", Event_RoundStart, EventHookMode_Pre);  //回合开始事件.
	
	l4d2_hCvar_tanklimit = CreateConVar("l4d2_hCvar_tank_limit", "3.0", "每个回合最多出现几个坦克?", FCVAR_NOTIFY, true, 0.0);

	
	HookConVarChange(l4d2_hCvar_tanklimit, eConvarChanged);

	
	CreateConVar("l4d2_tank_limit_version", PLUGIN_VERSION, "插件版本", FCVAR_NOTIFY);
	//AutoExecConfig(true, "l4d2_tank_limit_kk");
}

public void OnMapStart()
{
	CvarsChanged();
}

public void eConvarChanged(Handle hCvar, const char[] sOldVal, const char[] sNewVal)
{
	CvarsChanged();
}

void CvarsChanged()
{
	RoundTankLimit = l4d2_hCvar_tanklimit.IntValue;

}

//回合开始.
public void Event_RoundStart(Event event, const char[] name, bool dontBroadcast)
{
	RoundTankNum = false;

}



public void Event_Tank_Spawn(Event hEvent, const char[] sName, bool bDontBroadcast)
{
	int client = GetClientOfUserId(hEvent.GetInt("userid"));

	
	if (IsTank(client) && RoundTankNum >= RoundTankLimit)
	{
		
		ForcePlayerSuicide(client);
		
		
		if(RoundTankNum <= RoundTankLimit)
		{
			PrintToChatAll("\x05[公告]\x03TANK数量已经到达上限，本回合将不会再出现TANK!"); //聊天窗提示.
			PrintHintTextToAll("[公告]TANK数量已经到达上限，本回合将不会再出现TANK!"); //屏幕中下提示.
		}	
		
	}
	RoundTankNum = RoundTankNum + 1;

	
}


bool IsInfected(int client)
{
	return client > 0 && client <= MaxClients && IsClientInGame(client) && GetClientTeam(client) == 3;
}

bool IsTank(int client)  
{
	if (!IsInfected(client))
		return false;

	if (GetEntProp(client, Prop_Send, "m_zombieClass") != 8)
		return false;

	return true;
}


